package fiszkas

class Fiszka {

    public static final MAX_BOXES = 4

    static constraints = {
    }

    public static Fiszka createFiszka(props) {
        props.synonims = props.english.split(',').length
        return new Fiszka(props)
    }

    String polish
    String english

    int hits = 0
    int succs = 0
    int fails = 0
    int box = 0

    int synonims = 1

    Date lastPracticed = new Date(0)

    public inc() {
        if (this.box < this.MAX_BOXES - 1)
            this.box++

        this.hits++
        this.succs++
        this.lastPracticed = new Date()
    }

    public dec() {
        if (this.box > 0)
            this.box--

        this.hits++
        this.fails++
        this.lastPracticed = new Date()
    }

    @Override
    public String toString() {
        return "${this.id}: ${this.english}:${this.polish} (${this.succs}/${this.fails})"
    }
}
